<template>
  <div id="app">
    <router-view />
  </div>
</template>
<script>
import menus from '@/router/page';
export default {
  //下面是解决刷新页面丢失vuex数据
  created() {
    this.routerAdd();
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem('store')) {
      this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem('store'))));
    }

    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener('beforeunload', () => {
      sessionStorage.setItem('store', JSON.stringify(this.$store.state));
    });

    // this.$ELEMENT.size = localStorage.getItem("size") || "default";
    // const _store = this.$store;
    // window.onbeforeunload = function () {
    //   const { tabpageModule, adminModule } = _store.state;
    //   sessionStorage.setItem("listTag", JSON.stringify(tabpageModule.listTag));
    //   sessionStorage.setItem("user", JSON.stringify(adminModule.user));
    //   // sessionStorage.setItem("userModule", JSON.stringify(adminModule.userModule))
    // }
  },
  // mounted() {
  //   const _store = this.$store;
  //   let listTag = sessionStorage.getItem("listTag");
  //   let adminModule = sessionStorage.getItem("adminModule")
  //   let user = sessionStorage.getItem("user")
  //   if (listTag) {
  //     _store.state.tagsModule.listTag = JSON.parse(listTag)
  //   }
  //   if (adminModule) {
  //     Object.assign(_store.state.adminModule, JSON.parse(adminModule))
  //   }
  //   if (user) {
  //     _store.state.adminModule.user = JSON.parse(user)
  //   }
  // },
  methods: {
    // 动态添加路由
    routerAdd() {
      menus.forEach(item => {
        this.$router.addRoute("index", item);
      });
      this.$router.addRoute({
        path: "/:path(.*)+",
        redirect: "/vues"
      })
      //  console.log(this.$router.getRoutes())
    }
  }
}
</script>


<style>
/* 公共样式 */
/* 输入框 */
.box_container .box_input {
  text-align: left;
  margin-right: 15px;
}
.box_container .box_input .el-input {
  margin-right: 15px;
}
/* 下拉框 */
.box_input .el-select {
  margin-right: 10px;
}
/* 表格 */
.box_container .box_table {
  margin-top: 15px;
}
/* 分页 */
.box_container .box_paging {
  margin-top: 15px;
  text-align: left;
}
body {
  margin: 0px;
  padding: 0px;
}
.el-scrollbar__wrap {
  overflow-x: hidden;
}
/* 上传图片的样式 */
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 148px;
  height: 148px;
  /* line-height: 178px; */
  text-align: center;
}
.avatar {
  width: 148px;
  height: 148px;
  display: block;
}
</style>
